package cn.itcast.controller;

import cn.itcast.dto.OptLogDto;
import cn.itcast.event.SysLogEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description TODO
 * @Author 张开源
 * @Date 2022/4/9 23:20
 * @Version 1.0
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private ApplicationContext applicationContext;

    @RequestMapping("/getUser")
    public String getUser(){
        OptLogDto logDto = new OptLogDto();
        logDto.setRequestIp("127.0.0.0");
        logDto.setType("OPT");
        logDto.setUserName("admin");
        logDto.setDescription("查询用户信息");

        SysLogEvent event = new SysLogEvent(logDto);

        applicationContext.publishEvent(event);

        long id = Thread.currentThread().getId();
        System.out.println("发布事件,当前线程id:"+id);

        return "OK";

    }

}
